package ovm.entity;

import javax.persistence.*;
import java.sql.Timestamp;
import java.util.Collection;
import java.util.Date;

/**
 * Created by IntelliJ IDEA.
 * User: Jokser
 * Date: 26.05.12
 * Time: 8:16
 * To change this template use File | Settings | File Templates.
 */
@javax.persistence.Table(name = "TEACHING_MATERIAL", schema = "DBO_DIPLOM_NEW", catalog = "")
@Entity
public class TeachingMaterialEntity {
    private int id;

    @javax.persistence.Column(name = "ID")
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE)
    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    private String name;

    @javax.persistence.Column(name = "NAME")
    @Basic
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    private Date publishingDate;

    @javax.persistence.Column(name = "PUBLISHING_DATE")
    @Basic
    public Date getPublishingDate() {
        return publishingDate;
    }

    public void setPublishingDate(Date publishingDate) {
        this.publishingDate = publishingDate;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        TeachingMaterialEntity that = (TeachingMaterialEntity) o;

        if (id != that.id) return false;
        if (name != null ? !name.equals(that.name) : that.name != null) return false;
        if (publishingDate != null ? !publishingDate.equals(that.publishingDate) : that.publishingDate != null)
            return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = id;
        result = 31 * result + (name != null ? name.hashCode() : 0);
        result = 31 * result + (publishingDate != null ? publishingDate.hashCode() : 0);
        return result;
    }

    private DescriptionEntity descriptionByDescription;

    @ManyToOne
    public
    @javax.persistence.JoinColumn(name = "DESCRIPTION", referencedColumnName = "ID")
    DescriptionEntity getDescriptionByDescription() {
        return descriptionByDescription;
    }

    public void setDescriptionByDescription(DescriptionEntity descriptionByDescription) {
        this.descriptionByDescription = descriptionByDescription;
    }

    private PublishingEntity publishingByPublishing;

    @ManyToOne
    public
    @javax.persistence.JoinColumn(name = "PUBLISHING", referencedColumnName = "ID", nullable = false)
    PublishingEntity getPublishingByPublishing() {
        return publishingByPublishing;
    }

    public void setPublishingByPublishing(PublishingEntity publishingByPublishing) {
        this.publishingByPublishing = publishingByPublishing;
    }

    private Collection<TeachingMaterialAuthorsEntity> teachingMaterialAuthorsesById;

    @OneToMany(mappedBy = "teachingMaterialByTeachingMaterial")
    public Collection<TeachingMaterialAuthorsEntity> getTeachingMaterialAuthorsesById() {
        return teachingMaterialAuthorsesById;
    }

    public void setTeachingMaterialAuthorsesById(Collection<TeachingMaterialAuthorsEntity> teachingMaterialAuthorsesById) {
        this.teachingMaterialAuthorsesById = teachingMaterialAuthorsesById;
    }

    @Override
    public String toString() {
        return getName().trim();
    }

}
